/* Add here all your JS customizations */
$(document).ready(function() {
    $('.languagebtn').click(function () {
        $('.flags').toggle();
    });
    
    // Info popup --------------------
    $('.info').popover();
    $('.info-tooltip').tooltip(  );
    $(function() {
        $('[data-toggle="tooltip"]').tooltip();
    });


    // Language menu ------------------
    $('#languageId')
        .popover({
            html: true,
            title: 'Select language',
            content: $('#languageContent').html(),
            placement: 'bottom',
            trigger: 'manual'
        })
        .on('click', function(e) {
            var self = $(this);

            if ($('.popover').length > 0) {
                self.popover('hide');
            } else {
                self.popover('show');
            }

            // handle clicking on the popover itself
            $('.popover').off('click').on('click', function(e2) {
                e2.stopPropagation(); // prevent event for bubbling up => will not get caught with document.onclick
            });

            window.subscribeFlagsEvents();
            
            e.stopPropagation();
            return false;
        });
    // Product menu end ------------------


    // Product menu ------------------
    $('#popoverId')
        .popover({
            html: true,
            title: 'BIMobject&reg; Cloud Apps',
            content: $('#popoverContent').html(),
            placement: 'bottom',
            trigger: 'manual'
        })
        .on('click', function (e) {

            // Sets cookie
            //var date = new Date(); date.setTime(date.getTime() + (60 * 24 * 60 * 60 * 1000)); var expires = '; expires=' + date.toGMTString(); var domain = '; domain=.bimobject.com'; document.cookie = 'BIMobjectTooltipInfo=0' + expires + domain + '; path=/';

            // Hides tooltip
            $('#popoverId').tooltip('destroy');

            var self = $(this);

            if ($('.popover').length > 0) {
                self.popover('hide');
            } else {
                self.popover('show');
            }

            // handle clicking on the popover itself
            $('.popover').off('click').on('click', function(e2) {
                e2.stopPropagation(); // prevent event for bubbling up => will not get caught with document.onclick
            });

            $('.popover a[target="_blank"]').click(function() {
                self.popover('hide');
            });

            e.stopPropagation();
            return false;
        });
    
    $('body').on('click', function (e) {
        $('.popover-marker').each(function () {
            //the 'is' for buttons that trigger popups
            //the 'has' for icons within a button that triggers a popup
            if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
            }
        });
    });
    // Product menu end ------------------

    
    $(".fancybox").fancybox({
        padding: 0,
        autoSize: false,
        height: '90%',
        maxWidth: 700,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        iframe: { 'scrolling': 'yes' },
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-product-img").fancybox({
        padding: 0,
        autoSize: false,
        height: 600,
        maxWidth: 600,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-inbox").fancybox({
        padding: 0,
        autoSize: false,
        fitToView: false,
        width: '100%',
        maxWidth: 1000,
        height: '90%',
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        iframe: {'scrolling': 'yes'},
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-manufacturer").fancybox({
        padding: 0,
        autoSize: false,
        height: '90%',
        maxHeight: 600,
        width: '100%',
        maxWidth: 800,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-requestform").fancybox({
        padding: 0,
        autoSize: false,
        height: '90%',
        maxHeight: 650,
        width: '100%',
        maxWidth: 800,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-contactform").fancybox({
        padding: 0,
        autoSize: false,
        height: '90%',
        maxHeight: 550,
        width: '100%',
        maxWidth: 800,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-checkregistration").fancybox({
        padding: 0,
        autoSize: true,
        fitToView: false,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $(".fancybox-webgl").fancybox({
        padding: 0,
        autoSize: false,
        fitToView: false,
        width: '100%',
        maxWidth: 1000,
        height: '90%',
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        iframe: { 'scrolling': 'no' },
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
 
    $(".fancybox-login").fancybox({
        padding: 0,
        autoSize: true,
        fitToView: true,
        width: '100%',
        maxWidth: 420,
        height: '100%',
        maxHeight: 420,
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        iframe: { 'scrolling': 'yes' },
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
    $("#fancybox-webapp").fancybox({
        padding: 0,
        autoSize: false,
        fitToView: false,
        width: '98%',
        maxWidth: 1200,
        height: '98%',
        arrows: false,
        type: 'iframe',
        scrolling: 'no',
        iframe: { 'scrolling': 'yes' },
        transitionIn: 'none',
        transitionOut: 'none',
        helpers: {
            overlay: { closeClick: false }
        }
    });
});